class setUp extends eui.Component{

	private closeBtn:eui.Image;
	private downBtn:eui.Image;
	private downBtntxt:eui.Image;
	private musicBtn:eui.Image;
	private soundBtn:eui.Image;
    private skinObj:eui.Group;
	private alphaBg:eui.Image;
	public CLOSE:string = "close";
	public EXIT_ROOM:string = "exitRoom";

	private currentPosition:Array<any> = [true,true,1];//默认选项

	public constructor() {
		super();
		this.once(eui.UIEvent.COMPLETE,this.onComplete,this);
		this.skinName = "src/Game/gameRoom/window/setUpSkin.exml";
	}
    private onComplete(){
        this.once(egret.Event.REMOVED_FROM_STAGE,this.onRemove,this);
        StageData.MainObj.addEventListener(Events.STAGE_SIZE,this.onSize,this);
        this.init();
    }
    private onRemove(){
        this.closeBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_CLOSE,this);
		this.downBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_COMLPETE,this);
		this.musicBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_MUSIC,this);
		this.soundBtn.removeEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_SOUND,this);
        StageData.MainObj.removeEventListener(Events.STAGE_SIZE,this.onSize,this);
    }
    private onSize(){
		this.alphaBg.width = StageData.W;
        this.alphaBg.height = StageData.H;
        this.skinObj.x = (StageData.W - 886)/2;
        this.skinObj.y = (StageData.H - 605)/2;
    }

	private init(){//初始化  btnMode:1(切换账号),2（解散房间）,3（退出房间）		
		this.currentPosition[2] = 3;	
        this.currentPosition[0] = StageData.bgMusicClose;
        this.currentPosition[1] = StageData.soundClose;
		this.closeBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_CLOSE,this);
		this.downBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_COMLPETE,this);
		this.musicBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_MUSIC,this);
		this.soundBtn.addEventListener(egret.TouchEvent.TOUCH_TAP,this.FUN_SOUND,this);
		this.updateUi();
        this.onSize();
	}
	private FUN_MUSIC(){
		if(this.currentPosition[0]){
			this.currentPosition[0] = false;
		}else{
			this.currentPosition[0] = true;
		}
		StageData.bgMusicClose = this.currentPosition[0];
		StageData.MainObj.setBgMusic();
		egret.localStorage.setItem("bgMusicClose",String(StageData.bgMusicClose));
		this.updateUi();
	}
	private FUN_SOUND(){
		//GameData.soundObj.startSound("down");
		if(this.currentPosition[1]){
			this.currentPosition[1] = false;
		}else{
			this.currentPosition[1] = true;
		}
		StageData.soundClose = this.currentPosition[1];
		egret.localStorage.setItem("soundClose",String(StageData.soundClose));
		this.updateUi();
	}
	private FUN_COMLPETE(){//完成
		this.dispatchEventWith(this.EXIT_ROOM);
	}
	private FUN_CLOSE(){//关闭
		StageData.soundObj.startSound("down");
		this.dispatchEventWith(this.CLOSE);
	}	
	public getSetOption():Array<any>{//返回设置的选项
		return this.currentPosition;
	}
	
	/*.刷新ui显示.*/
	private updateUi(){		
		//音乐
		StageData.soundObj.startSound("down");
		if(this.currentPosition[0]){
			this.musicBtn.source = "s_soundK_png";
		}else{
			this.musicBtn.source = "s_soundN_png";
		}
		//音效
		if(this.currentPosition[1]){
			this.soundBtn.source = "s_soundK_png";
		}else{
			this.soundBtn.source = "s_soundN_png";
		}
		//底部按钮
		this.downBtntxt.source = "s_btnui"+this.currentPosition[2]+"_png";
	}
	
}